#include<iostream>
using namespace std;
long long n,a[200001],r,k[200001][3],ans;
bool bz[200001];
int main()
{
	cin>>n;
	cin>>a[1];
	r++;
	k[r][1]=1;
	bz[1]=true;
	for (int i=2;i<=n;i++)
	{
		cin>>a[i];
		bz[i]=true;
		if (a[i]!=a[i-1])
		{
			k[r][2]=i-1;
			r++;
			k[r][1]=i;
		}
	}
	k[r][2]=n;
	ans=n;
	while (ans>0)
	{
		cout<<endl;
		for (int j=1;j<=r;j++)
		{
			cout<<k[j][1]<<" "<<k[j][2]<<endl;
		}
		cout<<endl;
		for (int i=1;i<=r;i++)
		{
			while (bz[k[i][1]]==false)
			{
				k[i][1]++;
				if (k[i][1]>k[i][2])
				{
					break;
				}
			}
			bz[k[i][1]]=false;
			if (a[k[i][1]]==a[k[i+1][1]]&&i+1<r)
			{
				continue;
			}
			cout<<k[i][1]<<" ";
			k[i][1]++;
			ans--;
			if (ans==0)
			{
				break;
			}
		}
		if (ans==0)
		{
			break;
		}
		cout<<endl;
		for (int i=1;i<=r;i++)
		{
			if (a[k[i][1]]>a[k[i][2]])
			{
				for (int j=r;j>=i+1;j--)
				{
					k[j-1][1]=k[j][1];
					k[j-1][2]=k[j][2];
				}
				r--;
				i--;
			}
		}
		for (int i=2;i<=r;i++)
		{
			if (a[k[i][1]]==a[k[i-1][1]])
			{
				k[i-1][2]=k[i][2];
				for (int j=r;j>=i+1;j--)
				{
					k[j-1][1]=k[j][1];
					k[j-1][2]=k[j][2];
				}
				r--;
				i--;
			}
		}
	}
	return 0;
}
